const app = getApp();
const { AskPage } = app._require("common/index");
const { notesMixin } = app._require("pages/notes/action.js");
const formMixin = app._require("mixins/form.mixin.js").default;
AskPage({
  /**
   * 页面的初始数据
   */
  mixins: [notesMixin, formMixin],
  data: {
    navBarHeight: app.globalData.navBarHeight, //导航栏高度
    items: [
      {
        date: "",
      },
      {
        date: "",
      },
    ],
    categoryItems: [],
  },
  onLoad: function (options) {
    //1 待处理  2 已完成
    if (app.user.token.length > 0) {
      this.getDeclarationList();
      this.getDataAction();
      var value = wx.getStorageSync("common_use") || [];
      this.setData({
        useArr: value,
      });
    }
  },
  loginSuccess() {
    // console.log("----登录成功----");
    this.setData({
      user: app.user,
    });
    this.getDataAction();
    this.getDeclarationList();
    this.checkShowAlert();
  },
  onShow: function () {
    this.setData({
      user: app.user,
    });
    if (app.user.token.length == 0) {
      //清理数据
      this.setData({
        records: [],
        categoryItems: null,
      });
      return;
    }

    //检查微信
    this.checkShowAlert();
    //检查刷新
    var reoladData = wx.getStorageSync("reoladPage");
    if (reoladData) {
      if (reoladData["note"] == true) {
        this.getDeclarationList();
        this.getDataAction();
        reoladData["note"] = false;
        wx.setStorageSync("reoladPage", reoladData);
      }
    }

    // let that = this;
    let store_value = wx.getStorageSync("sb_report_reload");
    //刷新常用
    var value = wx.getStorageSync("common_use") || [];
    this.setData({
      useArr: value,
    });

    try {
      if (store_value && store_value.value == "1") {
        this.getDeclarationList();
        wx.setStorage({
          key: "sb_report_reload",
          data: {
            value: "0",
          },
        });
      }
    } catch (e) {}
  },
  reloadUse: function (e) {
    let useArr = e.detail.arr;
    this.setData({
        useArr: useArr
    })
},
  onPullDownRefresh() {
    if (app.user.token.length > 0) {
      this.getDataAction();
    }
  },
  async getDataAction() {
    const response = await this.$_server("home/categoryTree", {
      params: {},
    });
    let { data } = response;
    if (data.code != 200) {
      return;
    }
    try {
      let value = data.data[0].children;
      this.setData({
        categoryItems: value,
      });
    } catch (e) {}
  },
});
